package com.hjm.project.gearsRecord.gearsRecord.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.gearsRecord.gearsRecord.domain.GearsRecord;
import com.hjm.project.gearsRecord.gearsRecord.service.IGearsRecordService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 档位变更记录Controller
 * 
 * @author admin
 * @date 2020-11-23
 */
@Controller
@RequestMapping("/gearsRecord/gearsRecord")
public class GearsRecordController extends BaseController
{
    private String prefix = "gearsRecord/gearsRecord";

    @Autowired
    private IGearsRecordService gearsRecordService;

    @RequiresPermissions("gearsRecord:gearsRecord:view")
    @GetMapping()
    public String gearsRecord()
    {
        return prefix + "/gearsRecord";
    }

    /**
     * 查询档位变更记录列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GearsRecord gearsRecord)
    {
        startPage();
        List<GearsRecord> list = gearsRecordService.selectGearsRecordList(gearsRecord);
        return getDataTable(list);
    }

    /**
     * 导出档位变更记录列表
     */
    @RequiresPermissions("gearsRecord:gearsRecord:export")
    @Log(title = "档位变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GearsRecord gearsRecord)
    {
        List<GearsRecord> list = gearsRecordService.selectGearsRecordList(gearsRecord);
        ExcelUtil<GearsRecord> util = new ExcelUtil<GearsRecord>(GearsRecord.class);
        return util.exportExcel(list, "gearsRecord");
    }

    /**
     * 新增档位变更记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存档位变更记录
     */
    @RequiresPermissions("gearsRecord:gearsRecord:add")
    @Log(title = "档位变更记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GearsRecord gearsRecord)
    {
        return toAjax(gearsRecordService.insertGearsRecord(gearsRecord));
    }

    /**
     * 修改档位变更记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GearsRecord gearsRecord = gearsRecordService.selectGearsRecordById(id);
        mmap.put("gearsRecord", gearsRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存档位变更记录
     */
    @RequiresPermissions("gearsRecord:gearsRecord:edit")
    @Log(title = "档位变更记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GearsRecord gearsRecord)
    {
        return toAjax(gearsRecordService.updateGearsRecord(gearsRecord));
    }

    /**
     * 删除档位变更记录
     */
    @RequiresPermissions("gearsRecord:gearsRecord:remove")
    @Log(title = "档位变更记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gearsRecordService.deleteGearsRecordByIds(ids));
    }
}
